package com.heima.utils.common;

import com.heima.model.wemedia.pojos.WmUser;

public class WmThreadLocalUtil {

    private final static ThreadLocal<WmUser> threadLocal = new ThreadLocal<>();

    /**
     * 添加用户信息到ThreadLocal中
     * @param wmUser
     */
    public static void setUser(WmUser wmUser){
        threadLocal.set(wmUser);
    }

    /**
     * 从ThreadLocal获取用户信息
     * @return
     */
    public static WmUser getUser(){
        return threadLocal.get();
    }

    /**
     * 清理ThreadLocal中的用户信息（避免内存溢出）
     */
    public static void clear(){
        threadLocal.remove();
    }
}
